package yuanxing;

import java.util.ArrayList;

public class Person implements Cloneable {
    private String name;
    private Action action;//action是个对象
    private ArrayList<String> listStr = new ArrayList<>();//数组
    @Override
    public Object clone(){
        Person person = null;
        try {
            person = (Person) super.clone();//克隆已有的对象
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        person.name = this.name;//把已有的属性值复制给克隆的对象里的属性  8种基本类型可以用浅拷贝，其他用深拷贝
        person.action = (Action) this.action.clone();//要调用clone  深拷贝
        person.listStr = (ArrayList<String>) this.listStr.clone();//要调用clone 深拷贝
        return person;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Action getAction() {
        return action;
    }

    public void setAction(Action action) {
        this.action = action;
    }

    public ArrayList<String> getListStr() {
        return listStr;
    }

    public void setListStr(ArrayList<String> listStr) {
        this.listStr = listStr;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", action=" + action +
                ", listStr=" + listStr +
                '}';
    }
}
